<?php

class FileController extends BackendController
{
    public function actionDownload($id)
    {
        $modFile=$this->loadModel($id);

        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=" . $modFile->name);
        header("Content-Transfer-Encoding: binary ");

        readfile($modFile->source);
    }

    public function loadModel($id)
    {
        $modFile=Yii::app()->file->model->findByPk($id);
        if($modFile===null)
            throw new CHttpException(404,'The requested page does not exist.');
        return $modFile;
    }
}